Fix annotation default target warnings in enum constructors#602
Fix annotation default target warnings in enum constructors#602gioalex07 wants to merge 5 commits intoVREMSoftwareDevelopment:mainfrom
Conversation
Add explicit @param: target to @stringres, @DrawableRes and @ColorRes annotations on enum constructor parameters to suppress KT-73255 warnings. Kotlin 2.x will apply these annotations to both parameter and field by default in a future release; this change opts in to the parameter-only behavior explicitly. Affected files: WiFiBand, Strength, WiFiSecurity, WiFiStandard, WiFiWidth
|
Thanks for the contribution.
Please update the PR with real‑device testing details so review can continue. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #602 +/- ##
=========================================
Coverage 97.83% 97.83%
Complexity 975 975
=========================================
Files 121 121
Lines 2581 2581
Branches 211 211
=========================================
Hits 2525 2525
Misses 19 19
Partials 37 37 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Updates enum constructor resource annotations to silence Kotlin 2.x “default annotation target” warnings (KT-73255) by making the use-site target explicit.
Changes:
- Add explicit
@param:use-site targets for@StringRes,@DrawableRes, and@ColorReson enum constructorvalparameters. - Apply the change across 5 affected enums in
wifi/bandandwifi/model.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/WiFiWidth.kt | Adds @param:StringRes to enum constructor textResource. |
| app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/WiFiStandard.kt | Adds @param:StringRes to enum constructor fullResource / valueResource. |
| app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/WiFiSecurity.kt | Adds @param:DrawableRes / @param:StringRes to enum constructor properties. |
| app/src/main/kotlin/com/vrem/wifianalyzer/wifi/model/Strength.kt | Adds @param:DrawableRes / @param:ColorRes to enum constructor properties. |
| app/src/main/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiBand.kt | Adds @param:StringRes to enum constructor textResource. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| enum class Security( | ||
| @DrawableRes val imageResource: Int, | ||
| @param:DrawableRes val imageResource: Int, |
There was a problem hiding this comment.
@param:DrawableRes will annotate only the constructor parameter; since imageResource is a val constructor property that’s read elsewhere, the property itself will no longer be annotated as @DrawableRes. If you rely on resource-type checking when using security.imageResource, consider using @get:/@field: (or both targets) instead of parameter-only.
| enum class WiFiSecurityType( | ||
| val securityTypeId: SecurityTypeId, | ||
| @StringRes val textResource: Int, | ||
| @param:StringRes val textResource: Int, |
There was a problem hiding this comment.
Same concern here: @param:StringRes on a val constructor property annotates only the enum constructor parameter, not the textResource property that callers read later. If you want to keep WiFiSecurityType.textResource typed as @StringRes for lint/static checking, target the property (@get:/@field:) or apply both targets explicitly.
| @param:StringRes val textResource: Int, | |
| @param:StringRes @get:StringRes val textResource: Int, |
| @param:DrawableRes val imageResource: Int, | ||
| @param:ColorRes val colorResource: Int, |
There was a problem hiding this comment.
@param:DrawableRes / @param:ColorRes apply only to the enum constructor parameters. Since these are val constructor properties that are read later (e.g., strength.imageResource, strength.colorResource), this drops the resource annotations from the properties themselves and may reduce lint/resource-type checking at call sites. Consider targeting the property (@get:/@field:) or explicitly applying both targets.
| @param:DrawableRes val imageResource: Int, | |
| @param:ColorRes val colorResource: Int, | |
| @param:DrawableRes @get:DrawableRes val imageResource: Int, | |
| @param:ColorRes @get:ColorRes val colorResource: Int, |
|
|
||
| enum class WiFiBand( | ||
| @StringRes val textResource: Int, | ||
| @param:StringRes val textResource: Int, |
There was a problem hiding this comment.
@param:StringRes applies the annotation only to the constructor parameter; since this is a val constructor property, the generated textResource property/getter will no longer be annotated as a @StringRes. If this value is read elsewhere (e.g., passed into getString(...)), you likely want the annotation on the property as well (use @get:StringRes or @field:StringRes, or add both use-site targets explicitly).
| @param:StringRes val textResource: Int, | |
| @get:StringRes val textResource: Int, |
|
|
||
| enum class WiFiWidth( | ||
| @StringRes val textResource: Int, | ||
| @param:StringRes val textResource: Int, |
There was a problem hiding this comment.
Using @param:StringRes on a val constructor property means only the constructor parameter is annotated; the textResource property itself won’t carry @StringRes anymore. If callers read wiFiWidth.textResource and pass it to APIs expecting a @StringRes, consider targeting the property (@get:/@field:) or applying both targets explicitly to preserve resource-type safety while silencing KT-73255.
| @param:StringRes val textResource: Int, | |
| @param:StringRes @get:StringRes val textResource: Int, |
| @param:StringRes val fullResource: Int, | ||
| @param:StringRes val valueResource: Int, |
There was a problem hiding this comment.
@param:StringRes targets only the constructor parameter. Because fullResource/valueResource are val constructor properties that are accessed elsewhere, this change drops the @StringRes annotation from the property/getter/field, which may reduce lint/resource-type checking at call sites. Consider @get:/@field: (or duplicating targets) so the enum properties remain annotated.
| @param:StringRes val fullResource: Int, | |
| @param:StringRes val valueResource: Int, | |
| @get:StringRes val fullResource: Int, | |
| @get:StringRes val valueResource: Int, |
VREMSoftwareDevelopment
left a comment
There was a problem hiding this comment.
Thanks for the change — quick consistency suggestion based on the Copilot review noise (some suggestions were inconsistent).
Recommendation:
- Public constructor properties: annotate both parameter and getter so we get constructor-site and consumer-side checks: Example (from WiFiBand.kt): @get:StringRes @param:StringRes val textResource: Int
- Private constructor properties: annotate only the parameter: @param:LayoutRes private val layout: Int
Summary
@param:target to@StringRes,@DrawableResand@ColorResannotations on enum constructor parameters.What does this implement/fix?
Kotlin 2.x introduced a warning when
@StringRes,@DrawableResor@ColorResare applied to enum constructorparameters without an explicit annotation target. In a future release, these annotations will be applied to both
the parameter and the backing field by default. This change opts in to the parameter-only behavior explicitly
using the
@param:target, silencing the warning and future-proofing the code.Affected files:
wifi/band/WiFiBand.kt—@param:StringReswifi/model/Strength.kt—@param:DrawableRes,@param:ColorReswifi/model/WiFiSecurity.kt—@param:DrawableRes,@param:StringReswifi/model/WiFiStandard.kt—@param:StringRes(x2)wifi/model/WiFiWidth.kt—@param:StringResDoes this close any issues?
How was this tested?